home *** CD-ROM | disk | FTP | other *** search
/ Champak 54 / Vol 54.iso / games / wiggi_wa.swf / scripts / DefineSprite_290 / frame_1 / DoAction.as
Encoding:
Text File  |  2007-09-27  |  14.2 KB  |  591 lines

  1. function onEnterFrame()
  2. {
  3.    pauseManagement();
  4.    if(gamePaused == false)
  5.    {
  6.       levelTimer += 0.04;
  7.       levelTimerDisplay = Math.round(levelTimer);
  8.       touchBuffer--;
  9.       function_heroDeathManagement();
  10.       function_HERO();
  11.       function_CAMERA(camTarget,camElasticStore,camTypeStore,camXPos,camYPos);
  12.    }
  13. }
  14. function pauseManagement()
  15. {
  16.    if(Key.isDown(77) and pauseSwitch == false)
  17.    {
  18.       pauseSwitch = true;
  19.       if(gamePaused == false)
  20.       {
  21.          gamePaused = true;
  22.       }
  23.       else
  24.       {
  25.          gamePaused = false;
  26.       }
  27.    }
  28.    else if(Key.isDown(77) == false)
  29.    {
  30.       pauseSwitch = false;
  31.    }
  32. }
  33. function function_HERO()
  34. {
  35.    if(HERO.dead == false and HERO.win == false)
  36.    {
  37.       function_HERO_jump();
  38.       function_gravity(this.HERO);
  39.       function_HERO_hitRoof();
  40.       function_HERO_hitGround();
  41.       function_HERO_spriteGraphics();
  42.       function_HERO_healthManagement();
  43.       function_dangers();
  44.       if(heroHitForeground() == true)
  45.       {
  46.          if(this.FOREGROUND._alpha > 50)
  47.          {
  48.             this.FOREGROUND._alpha -= 5;
  49.          }
  50.       }
  51.       else if(this.FOREGROUND._alpha < 100)
  52.       {
  53.          this.FOREGROUND._alpha += 5;
  54.       }
  55.       function_HERO_hitWall(this.HERO.charWidth / 2,(- this.HERO.charHeight) / 2,1);
  56.       function_HERO_hitWall((- this.HERO.charWidth) / 2,(- this.HERO.charHeight) / 2,-1);
  57.       function_HERO_move();
  58.    }
  59.    else if(HERO.win == true)
  60.    {
  61.       function_gravity(this.HERO);
  62.       function_heroWinManagement();
  63.       function_HERO_hitGround();
  64.    }
  65. }
  66. function function_HERO_move()
  67. {
  68.    if(Key.isDown(39) and HERO.paralysisTimer == 0)
  69.    {
  70.       if(this.HERO.speed < this.HERO.maxSpeed)
  71.       {
  72.          this.HERO.speed += this.HERO.accel;
  73.       }
  74.       else
  75.       {
  76.          this.HERO.speed = this.HERO.maxSpeed;
  77.       }
  78.    }
  79.    else if(Key.isDown(37) and HERO.paralysisTimer == 0)
  80.    {
  81.       if(this.HERO.speed > - this.HERO.maxSpeed)
  82.       {
  83.          this.HERO.speed -= this.HERO.accel;
  84.       }
  85.       else
  86.       {
  87.          this.HERO.speed = - this.HERO.maxSpeed;
  88.       }
  89.    }
  90.    else
  91.    {
  92.       this.HERO.speed /= this.HERO.deccel;
  93.    }
  94.    if(Key.isDown(dashKey) == false)
  95.    {
  96.       this.HERO.speed /= this.HERO.dashSpeed;
  97.    }
  98.    this.HERO._x += this.HERO.speed;
  99. }
  100. function function_HERO_jump()
  101. {
  102.    if(HERO.paralysisTimer == 0)
  103.    {
  104.       if(Key.isDown(jumpKey) and touchBuffer > 0 and this.HERO.jumpLock == false)
  105.       {
  106.          _parent.STAGE.newSound("Sound_Jump");
  107.          this.HERO.jumpLock = true;
  108.          this.HERO.drop = - this.HERO.jumpHeight;
  109.       }
  110.       if(HERO.drop >= (- HERO.jumpHeight) / 2 and Key.isDown(jumpKey) == false and doubleJumpCount < HERO.doubleJumps)
  111.       {
  112.          allowDoubleJump = true;
  113.       }
  114.       if(Key.isDown(jumpKey) and allowDoubleJump == true)
  115.       {
  116.          allowDoubleJump = false;
  117.          doubleJumpCount++;
  118.          this.HERO.drop = (- this.HERO.doubleJumpHeight) / doubleJumpDegrade;
  119.          doubleJumpDegrade += HERO.doubleJumpDegrade;
  120.       }
  121.       if(Key.isDown(jumpKey) == false and touchBuffer > 0)
  122.       {
  123.          this.HERO.jumpLock = false;
  124.       }
  125.    }
  126. }
  127. function function_CAMERA(camTarg, camSpeed, camType, xPos, yPos)
  128. {
  129.    if(Key.isDown(65) == false)
  130.    {
  131.       if(Key.isDown(camKeyUp))
  132.       {
  133.          camYOffset = 100;
  134.       }
  135.       else if(Key.isDown(camKeyDown))
  136.       {
  137.          camYOffset = -100;
  138.       }
  139.       else
  140.       {
  141.          camYOffset = 0;
  142.       }
  143.       if(Key.isDown(camKeyRight))
  144.       {
  145.          camXOffset = -100;
  146.       }
  147.       else if(Key.isDown(camKeyLeft))
  148.       {
  149.          camXOffset = 100;
  150.       }
  151.       else
  152.       {
  153.          camXOffset = 0;
  154.       }
  155.       if(camType == 1)
  156.       {
  157.          this._x += (xPos - camTarg._x - this._x + camXOffset) / camSpeed;
  158.          this._y += (yPos - camTarg._y - this._y + camYOffset) / camSpeed;
  159.       }
  160.       else if(camType == 2)
  161.       {
  162.          this._x += (xPos - camTarg._x - this._x + camXOffset) / camSpeed;
  163.       }
  164.       else if(camType == 3)
  165.       {
  166.          this._y += (yPos - camTarg._y - this._y + camYOffset) / camSpeed;
  167.       }
  168.    }
  169. }
  170. function heroHitGround()
  171. {
  172.    if(this.GROUND.hitTest(this.HERO._x + this._x,this.HERO._y + this._y,true))
  173.    {
  174.       if(HERO.drop == WORLD_gravity and touchBuffer < -18)
  175.       {
  176.          _parent.STAGE.newSound("Sound_Thud");
  177.          function_newParticle(HERO._x,1,"Particle_FallSmoke",1);
  178.          function_newParticle(HERO._x,0,"Particle_FallSmoke",1);
  179.       }
  180.       HERO.drop = 0;
  181.       touchBuffer = 6;
  182.       doubleJumpCount = 0;
  183.       doubleJumpDegrade = 1;
  184.       return true;
  185.    }
  186. }
  187. function heroHitForeground()
  188. {
  189.    if(this.FOREGROUND.hitTest(this.HERO._x + this._x,this.HERO._y + this._y,true))
  190.    {
  191.       return true;
  192.    }
  193. }
  194. function heroHitWall(wallXPos, wallYPos)
  195. {
  196.    if(this.GROUND.hitTest(this.HERO._x + wallXPos + this._x,this.HERO._y + wallYPos + this._y,true))
  197.    {
  198.       return true;
  199.    }
  200. }
  201. function function_HERO_hitWall(wallXPos, wallYPos, wallDir)
  202. {
  203.    if(heroHitWall(wallXPos,wallYPos) == true)
  204.    {
  205.       while(heroHitWall(wallXPos,wallYPos) == true)
  206.       {
  207.          this.HERO._x -= wallDir;
  208.       }
  209.       this.HERO.speed = 0;
  210.    }
  211. }
  212. function heroHitRoof()
  213. {
  214.    if(this.GROUND.hitTest(this.HERO._x + this._x,this.HERO._y + this._y - this.HERO.charHeight,true))
  215.    {
  216.       return true;
  217.    }
  218. }
  219. function function_HERO_hitRoof()
  220. {
  221.    if(heroHitRoof() == true)
  222.    {
  223.       while(heroHitRoof() == true)
  224.       {
  225.          this.HERO._y = this.HERO._y + 1;
  226.       }
  227.       this.HERO.drop = 1;
  228.    }
  229. }
  230. function function_HERO_hitGround()
  231. {
  232.    if(heroHitGround() == true)
  233.    {
  234.       while(heroHitGround() == true)
  235.       {
  236.          this.HERO._y--;
  237.          this.HERO.drop = 0;
  238.       }
  239.       this.HERO._y += 1;
  240.    }
  241. }
  242. function function_gravity(characterClass)
  243. {
  244.    characterClass._y += characterClass.drop;
  245.    if(characterClass.drop < WORLD_gravity)
  246.    {
  247.       characterClass.drop += WORLD_airResistance;
  248.    }
  249.    else
  250.    {
  251.       characterClass.drop = WORLD_gravity;
  252.    }
  253. }
  254. function processInputKeys()
  255. {
  256.    var _loc2_ = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
  257.    var _loc3_ = new Array(65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90);
  258.    var _loc1_ = 0;
  259.    while(_loc1_ < 26)
  260.    {
  261.       if(jumpKey == _loc2_[_loc1_])
  262.       {
  263.          jumpKey = _loc3_[_loc1_];
  264.       }
  265.       _loc1_ = _loc1_ + 1;
  266.    }
  267.    _loc1_ = 0;
  268.    while(_loc1_ < 26)
  269.    {
  270.       if(attackKey == _loc2_[_loc1_])
  271.       {
  272.          attackKey = _loc3_[_loc1_];
  273.       }
  274.       _loc1_ = _loc1_ + 1;
  275.    }
  276.    _loc1_ = 0;
  277.    while(_loc1_ < 26)
  278.    {
  279.       if(dashKey == _loc2_[_loc1_])
  280.       {
  281.          dashKey = _loc3_[_loc1_];
  282.       }
  283.       _loc1_ = _loc1_ + 1;
  284.    }
  285.    if(dashKey == null)
  286.    {
  287.       HERO.dashSpeed = 1;
  288.    }
  289. }
  290. function function_HERO_spriteGraphics()
  291. {
  292.    if(HERO.paralysisTimer > 0)
  293.    {
  294.       HERO.sprite.gotoAndStop("HURT");
  295.       HERO.paralysisTimer--;
  296.    }
  297.    else if(touchBuffer < 3)
  298.    {
  299.       HERO.sprite.gotoAndStop("JUMP");
  300.    }
  301.    else if(Key.isDown(39))
  302.    {
  303.       if(Key.isDown(dashKey) or dashKey == null)
  304.       {
  305.          HERO.sprite.gotoAndStop("RUN");
  306.       }
  307.       else
  308.       {
  309.          HERO.sprite.gotoAndStop("WALK");
  310.       }
  311.       HERO.sprite._xscale = HERO.spriteScale;
  312.    }
  313.    else if(Key.isDown(37))
  314.    {
  315.       if(Key.isDown(dashKey) or dashKey == null)
  316.       {
  317.          HERO.sprite.gotoAndStop("RUN");
  318.       }
  319.       else
  320.       {
  321.          HERO.sprite.gotoAndStop("WALK");
  322.       }
  323.       HERO.sprite._xscale = - HERO.spriteScale;
  324.    }
  325.    else
  326.    {
  327.       HERO.sprite.gotoAndStop("STAND");
  328.    }
  329. }
  330. function defaultCamera()
  331. {
  332.    camTarget = camTarget_default;
  333.    camTypeStore = camTypeStore_default;
  334.    camElasticStore = camElasticStore_default;
  335.    camXPos = camXPos_default;
  336.    camYPos = camYPos_default;
  337. }
  338. function function_dangers()
  339. {
  340.    if(this.DANGERS.hitTest(this.HERO._x + this._x,this.HERO._y + this._y,true))
  341.    {
  342.       function_HERO_hurt();
  343.    }
  344. }
  345. function function_HERO_hurt()
  346. {
  347.    if(HERO.invTimer == 0)
  348.    {
  349.       _parent.STAGE.newSound("Sound_Hurt");
  350.       if(HERO.sprite._xscale > 0)
  351.       {
  352.          HERO.speed = -10;
  353.       }
  354.       else
  355.       {
  356.          HERO.speed = 10;
  357.       }
  358.       HERO.drop = -20;
  359.       HERO.paralysisTimer = HERO.paralysisTime;
  360.       HERO.invTimer = HERO.invTime;
  361.       HERO.health--;
  362.    }
  363. }
  364. function function_HERO_healthManagement()
  365. {
  366.    if(HERO.invTimer > 0)
  367.    {
  368.       HERO.invTimer--;
  369.       if(HERO.paralysisTimer == 0)
  370.       {
  371.          HERO.sprite._alpha = - HERO.sprite._alpha;
  372.       }
  373.       else
  374.       {
  375.          HERO.sprite._alpha = 100;
  376.       }
  377.    }
  378.    else
  379.    {
  380.       HERO.sprite._alpha = 100;
  381.    }
  382. }
  383. function function_newParticle(xPos, yPos, MC, number)
  384. {
  385.    var _loc2_ = 0;
  386.    while(_loc2_ < number)
  387.    {
  388.       var _loc1_ = EFFECTS.attachMovie(MC,"P" + effectCount,effectCount++);
  389.       _loc1_._x = xPos;
  390.       _loc1_._y = yPos;
  391.       _loc2_ = _loc2_ + 1;
  392.    }
  393. }
  394. function enemy(classID)
  395. {
  396.    if(ENEMIES[classID].hitTest(_parent.STAGE))
  397.    {
  398.       if(ENEMIES[classID].hitTest(HERO.feet) and HERO.drop > 5)
  399.       {
  400.          if(Key.isDown(jumpKey))
  401.          {
  402.             HERO.drop = (- HERO.drop) * 1.5;
  403.          }
  404.          else
  405.          {
  406.             HERO.drop = - HERO.drop;
  407.          }
  408.          function_newParticle(ENEMIES[classID]._x,ENEMIES[classID]._y,"Class_Particle_Enemy",50);
  409.          ENEMIES[classID].swapDepths(0);
  410.          ENEMIES[classID].removeMovieClip();
  411.       }
  412.       else if(ENEMIES[classID].hitTest(HERO.body))
  413.       {
  414.          function_HERO_hurt();
  415.       }
  416.    }
  417.    ENEMIES[classID]._y += ENEMIES[classID].drop;
  418.    if(ENEMIES[classID].drop < WORLD_gravity)
  419.    {
  420.       ENEMIES[classID].drop += WORLD_airResistance;
  421.    }
  422.    if(enemy_groundHit(0,0,classID) == true)
  423.    {
  424.       while(enemy_groundHit(0,0,classID) == true)
  425.       {
  426.          ENEMIES[classID]._y--;
  427.       }
  428.       ENEMIES[classID]._y = ENEMIES[classID]._y + 1;
  429.       ENEMIES[classID].drop = 0;
  430.    }
  431.    if(enemy_groundHit(40,-20,classID) == true or enemy_enemyHit(40,-20,classID) == true)
  432.    {
  433.       ENEMIES[classID].moveDir = -1;
  434.    }
  435.    else if(enemy_groundHit(-40,-20,classID) == true or enemy_enemyHit(-40,-20,classID) == true)
  436.    {
  437.       ENEMIES[classID].moveDir = 1;
  438.    }
  439.    enemy_speedControl(classID);
  440. }
  441. function enemy_groundHit(xPos, yPos, classID)
  442. {
  443.    if(GROUND.hitTest(ENEMIES[classID]._x + _X + xPos,ENEMIES[classID]._y + _Y + yPos,true))
  444.    {
  445.       return true;
  446.    }
  447.    if(ENEMIES.hitTest(ENEMIES[classID]._x + _X + xPos,ENEMIES[classID]._y + _Y + yPos + 5,true))
  448.    {
  449.       return true;
  450.    }
  451. }
  452. function enemy_enemyHit(xPos, yPos, classID)
  453. {
  454.    if(ENEMIES.hitTest(ENEMIES[classID]._x + _X + xPos,ENEMIES[classID]._y + _Y + yPos,true))
  455.    {
  456.       return true;
  457.    }
  458. }
  459. function enemy_speedControl(classID)
  460. {
  461.    if(ENEMIES[classID].moveDir == 1)
  462.    {
  463.       if(ENEMIES[classID].speed < 5)
  464.       {
  465.          ENEMIES[classID].speed = ENEMIES[classID].speed + 1;
  466.       }
  467.    }
  468.    else if(ENEMIES[classID].speed > -5)
  469.    {
  470.       ENEMIES[classID].speed--;
  471.    }
  472.    ENEMIES[classID]._x += ENEMIES[classID].speed;
  473. }
  474. function function_heroDeathManagement()
  475. {
  476.    if(HERO.health == 0)
  477.    {
  478.       if(deathDelay > 0)
  479.       {
  480.          deathDelay--;
  481.       }
  482.       else
  483.       {
  484.          deathDelay = 10;
  485.          HERO.dead = true;
  486.          HERO._visible = false;
  487.          _parent.STAGE.newSound("Sound_Glass");
  488.          function_newParticle(HERO._x,HERO._y,"Class_Particle_Dead",100);
  489.          function_newParticle(HERO._x,HERO._y - 20,"Class_Particle",50);
  490.          HERO.health = 1;
  491.          HERO.drop = -10;
  492.       }
  493.    }
  494.    if(HERO.dead == true)
  495.    {
  496.       if(HERO.deadTimer < 30)
  497.       {
  498.          HERO.deadTimer = HERO.deadTimer + 1;
  499.          if(HERO.deadTimer == 30)
  500.          {
  501.             _parent.STAGE.newSound("Sound_Swoosh");
  502.          }
  503.       }
  504.       else if(HERO.deadTimer < 60)
  505.       {
  506.          HERO._x += (heroStartX - HERO._x) / 10;
  507.          HERO._y = (heroStartY - HERO._y) / 10;
  508.          HERO.deadTimer = HERO.deadTimer + 1;
  509.       }
  510.       else
  511.       {
  512.          HERO._x = heroStartX + 30;
  513.          HERO._y = heroStartY - 10;
  514.          function_newParticle(HERO._x,HERO._y - 20,"Class_Particle",50);
  515.          _parent.STAGE.newSound("Sound_Glass");
  516.          HERO.dead = false;
  517.          HERO._visible = true;
  518.          HERO.deadTimer = 0;
  519.          HERO.invTimer = 0;
  520.       }
  521.    }
  522. }
  523. function function_heroWinManagement()
  524. {
  525.    if(heroHitGround() == true)
  526.    {
  527.       while(heroHitGround() == true)
  528.       {
  529.          HERO._y--;
  530.       }
  531.       HERO.drop = -15;
  532.       HERO.sprite._xscale = - HERO.sprite._xscale;
  533.    }
  534.    HERO.sprite.gotoAndStop("JUMP");
  535. }
  536. var jumpKey = 32;
  537. var attackKey = "D";
  538. var dashKey = null;
  539. var camKeyLeft = null;
  540. var camKeyRight = null;
  541. var camKeyUp = null;
  542. var camKeyDown = null;
  543. this.HERO.maxSpeed = 10;
  544. this.HERO.accel = 1;
  545. this.HERO.deccel = 1.2;
  546. this.HERO.jumpHeight = 25;
  547. this.HERO.doubleJumps = 0;
  548. this.HERO.doubleJumpHeight = 0;
  549. this.HERO.doubleJumpDegrade = 0;
  550. this.HERO.charWidth = 30;
  551. this.HERO.charHeight = 40;
  552. this.HERO.dashSpeed = 1.2;
  553. this.HERO.paralysisTime = 30;
  554. this.HERO.invTime = 120;
  555. this.HERO.deadTimerStore = 60;
  556. this.HERO.health = 1;
  557. var camTarget_default = this.HERO;
  558. var camTypeStore_default = 1;
  559. var camElasticStore_default = 5;
  560. var camXPos_default = 400;
  561. var camYPos_default = 300;
  562. var WORLD_gravity = 20;
  563. var WORLD_airResistance = 2;
  564. LEVEL = _parent.levelArray[_parent.levelID];
  565. HERO.deadTimer = 0;
  566. var heroStartX = HERO._x;
  567. var heroStartY = HERO._y;
  568. HERO.dead = false;
  569. defaultCamera();
  570. processInputKeys();
  571. HERO.spriteScale = HERO.sprite._xscale;
  572. var doubleJumpCount = 0;
  573. var doubleJumpDegrade = 0;
  574. var allowDoubleJump = false;
  575. createEmptyMovieClip("EFFECTS",1);
  576. _quality = "medium";
  577. deathDelay = 10;
  578. levelTimer = 0;
  579. levelTimerDisplay = levelTimer;
  580. itemCollect = 0;
  581. gamePaused = false;
  582. this.HERO.drop = 0;
  583. this.HERO.speed = 0;
  584. this.HERO.jumpSwitch = false;
  585. this.HERO.jumpLock = false;
  586. this.HERO.invTimer = 0;
  587. this.HERO.paralysisTimer = 0;
  588. HERO.win = false;
  589. effectCount = 0;
  590. enemyID = 0;
  591.